#import <UIKit/UIKit.h>

#import "FWApplication.h"


extern NSString* const FWDetailListViewFieldTitle;
extern NSString* const FWDetailListViewFieldTitleInfo;
extern NSString* const FWDetailListViewFieldMessage;
extern NSString* const FWDetailListViewFieldValue;
extern NSString* const FWDetailListViewFieldNoBold;
extern NSString* const FWDetailListViewFieldSize;
extern NSString* const FWDetailListViewFieldIcon;
extern NSString* const FWDetailListViewFieldLines;
extern NSString* const FWDetailListViewFieldColor;
extern NSString* const FWDetailListViewFieldBGColor;
extern NSString* const FWDetailListViewFieldProgress;
extern NSString* const FWDetailListViewFieldSwitch;
extern NSString* const FWDetailListViewFieldSelected;
extern NSString* const FWDetailListViewFieldIsLink;
extern NSString* const FWDetailListViewFieldIsBackLink;

extern NSString* const FWDetailListViewSectionTitle;
extern NSString* const FWDetailListViewSectionContents;


@protocol FWDetailListViewDelegate <NSObject>

//- (NSArray*)dataForIndex:(NSInteger)i list:(NSArray*)list database:(NSString*)dbpath application:(FWApplication*)application;
- (NSArray*)dataForDetailListPage:(NSObject*)page application:(FWApplication*)application;


@optional

- (BOOL)cancelClicked:(FWApplication*)application sections:(NSArray*)sections;
- (BOOL)doneClicked:(FWApplication*)application sections:(NSArray*)sections;
- (BOOL)selectClicked:(FWApplication*)application sections:(NSArray*)sections;

- (NSArray*)listPageInfoForKey:(NSNumber*)key currentPage:(NSObject*)page displayDepth:(NSInteger)depth application:(FWApplication*)application;
- (NSString*)captionForListPage:(NSObject*)page forKey:(NSNumber*)key displayDepth:(NSInteger)depth application:(FWApplication*)application;

@end


@interface FWDetailListView : UIView <UITableViewDataSource, UITableViewDelegate, UINavigationBarDelegate>
{
    NSInteger index;
    NSArray* sections;
    NSString* caption;
    NSMutableArray* linkStack;
}


@property (nonatomic, retain) id<FWDetailListViewDelegate> delegate;
@property (retain) FWApplication* application;
@property (assign) NSInteger index;
@property (nonatomic, retain) NSArray* list;
@property (nonatomic, retain) NSString* caption;
@property (retain) UITableView* view;
@property (retain) UISegmentedControl* navControl;
@property (retain) UINavigationBar* navBar;
@property (nonatomic, retain) NSArray* sections;
@property (retain) NSMutableArray* linkStack;

@property (assign) CGFloat reloadViewOffset;
@property (assign) BOOL reloadViewAnimated;


+ (NSDictionary*)sectionEntryForElements:(NSArray*)elements;
+ (NSDictionary*)sectionEntryForElements:(NSArray*)elements withTitle:(NSString*)title;

- (id)initWithFrame:(CGRect)r list:(NSArray*)l index:(NSInteger)i application:(FWApplication*)app delegate:(id<FWDetailListViewDelegate>)d;
- (id)initWithFrame:(CGRect)r list:(NSArray*)l index:(NSInteger)i caption:(NSString*)caption application:(FWApplication*)app delegate:(id<FWDetailListViewDelegate>)d;
- (void)dealloc;

- (void)buildPreview:(CGRect)rect;

- (void)reloadData:(BOOL)animated;

@end
